<template>
  <view class="systemMessage-container">
    <customtop top_title="一手资源"></customtop>
    <view class="content">
      <template v-for="(item, index) in resourceList">
        <resourceItem
          :item="item"
          @getDetailClick="getDetailClick"
        ></resourceItem>
      </template>
    </view>
  </view>
</template>

<script>
import customtop from "@/components/customtop.vue";
import resourceItem from "@/components/resource/index.vue";
import { request } from "@/utils/http.js";
export default {
  components: { customtop, resourceItem },
  data() {
    return {
      resourceList: [],
      params: {
        page_size: 15,
        page: 1,
      },
    };
  },
  onLoad(options) {
    this.getList();
  },
  onReachBottom() {
    this.params.page++;
    this.getList();
    console.log("触底");
  },
  methods: {
    getDetailClick(item) {
      const { id } = item;
      this.$u.route("/pages/message/resourceDetail?id=" + id);
    },
    getList() {
      request
        .post("/yishouzixun/getAllList", { ...this.params })
        .then((res) => {
          if (
            res.data.data.length > 0 &&
            this.params.page <= res.data.last_page
          ) {
            this.resourceList = this.resourceList.concat(res.data.data);
            console.log(this.resourceList, res.data.data);
          } else if (this.params.page >= 1) {
            this.params.page--;
          }
        });
    },
  },
};
</script>

<style lang="scss" scoped></style>
